/**
 * 
 */
package org.crystal.jqweb.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.crystal.jqweb.JqWebActionSupport;
import org.crystal.jqweb.ajaxtree.AjaxAdubyTree;
import org.crystal.jqweb.json.JsonSerialize;
import org.crystal.jqweb.service.JqWebBack;

/**
 * @author Crystal
 *
 */
public class AdubyTreeAction extends JqWebActionSupport {
	
	private static int i=1;

	/**
	 * 
	 */
	public AdubyTreeAction() {
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see org.crystal.jqweb.JqWebActionSupport#execute(java.util.HashMap)
	 */
	@Override
	public JqWebBack execute(HashMap<String, String> request) {
		// TODO Auto-generated method stub
		JsonSerialize jsons=new JsonSerialize();

		List listAdubyTree =new ArrayList();
		
		if(request.get("id").equals("-1")){
			AjaxAdubyTree aat=new AjaxAdubyTree();
			aat.setId("node_"+i);
			aat.setData("node_"+i);
			aat.setPid("-1");
			aat.setJsaction("javascript:void(0);");
			aat.setHaschild(true);
			listAdubyTree.add(aat);
			i++;
			
		}else{
			for(int j=0;j<4;j++){  
				AjaxAdubyTree aat=new AjaxAdubyTree();
				aat.setId("node_"+i);
				aat.setData("node_"+i);
				aat.setPid(request.get("id"));
				aat.setJsaction("javascript:void(0);");
				aat.setHaschild(true);
				listAdubyTree.add(aat);
				i++;
			}
		}
		
		String json=jsons.toJsonString(listAdubyTree);
		back.backJson(json);
		return back;
	}

}
